package com.twotiger.and.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import app.twotiger.p2p.R;

import com.twotiger.and.Constants;
import com.twotiger.and.activity.WebViewPage;
import com.twotiger.and.activity.base.AbastractListItem;
import com.twotiger.and.activity.base.AbastractListItem.OnClick;
import com.twotiger.and.activity.base.BaseActivity;
import com.twotiger.and.activity.base.BaseListItemLayout2;
import com.twotiger.and.activity.project.ProjectDetailPage;
import com.twotiger.and.bean.Basebean;
import com.twotiger.and.bean.DebtProjectdetailData;
import com.twotiger.and.bean.ProjectdetailData;

public class ProjectDetaillistAdpter extends BaseListAdapter {

    public ProjectDetaillistAdpter() {

    }

    public ProjectDetaillistAdpter(BaseActivity mActivity, Basebean projectdetail) {
        this.mActivity = mActivity;
        if (projectdetail instanceof ProjectdetailData) {
            this.datas = initList((ProjectdetailData) projectdetail);
        } else if (projectdetail instanceof DebtProjectdetailData) {
            this.datas = initList2((DebtProjectdetailData) projectdetail);
        }
    }

    //  1、项目详情接口：projectDetail
    //   借款方信息：http://test.twotiger.net:1130/app2/projectDetail?projectId=6#jkfxx
    //   借款用途：http://test.twotiger.net:1130/app2/projectDetail?projectId=6#jkyt
    //   借款来源：http://test.twotiger.net:1130/app2/projectDetail?projectId=6#hkly
    //   资质审核：http://test.twotiger.net:1130/app2/projectDetail?projectId=6#zzsh
    //   全部：http://test.twotiger.net:1130/app2/projectDetail?projectId=6

    private List<AbastractListItem> initList(final ProjectdetailData projectdetail) {
        ArrayList<AbastractListItem> tmp = new ArrayList<AbastractListItem>();
        AbastractListItem item1 = new ProjectDetailItem("借款人信息", R.drawable.project_detail_v2_1,
            projectdetail.getLoanPeopleSimple(), new itemClick(
                Constants.project_detail_introduction + projectdetail.getProjectId() + "#jkfxx",
                "项目介绍"));
        AbastractListItem item2 = new ProjectDetailItem("借款用途", R.drawable.project_detail_v2_2,
            projectdetail.getLoanUseSimple(), new itemClick(Constants.project_detail_introduction
                                                            + projectdetail.getProjectId()
                                                            + "#jkyt", "项目介绍"));
        AbastractListItem item3 = new ProjectDetailItem("还款来源", R.drawable.project_detail_v2_3,
            projectdetail.getRepaymentWaySimple(), new itemClick(
                Constants.project_detail_introduction + projectdetail.getProjectId() + "#hkly",
                "项目介绍"));
        AbastractListItem item4 = new ProjectDetailItem("资质审核", R.drawable.project_detail_v2_4,
            projectdetail.getCertAuditSimple(), new itemClick(Constants.project_detail_introduction
                                                              + projectdetail.getProjectId()
                                                              + "#zzsh", "项目介绍"));
        AbastractListItem item5 = new ProjectDetailItem("查看全部信息", R.drawable.project_detail_v2_5,
            null, new OnClick() {

                @Override
                public void onClick() {
                    Intent intent = new Intent(mActivity, WebViewPage.class);
                    intent.putExtra("url",
                        Constants.project_detail_introduction + projectdetail.getProjectId());
                    intent.putExtra("title", "项目介绍");
                    intent.putExtra("PROJECTDETAIL", projectdetail);
                    mActivity.startNewActivityforresult(intent, R.anim.push_left_in,
                        R.anim.push_left_out, ProjectDetailPage.TENDERREQUEST);
                }
            });
        tmp.add(item1);
        tmp.add(item2);
        tmp.add(item3);
        tmp.add(item4);
        tmp.add(item5);
        return tmp;
    }
    private List<AbastractListItem> initList2(final DebtProjectdetailData projectdetail) {
        ArrayList<AbastractListItem> tmp = new ArrayList<AbastractListItem>();
        AbastractListItem item1 = new ProjectDetailItem("借款人信息", R.drawable.project_detail_v2_1,
            projectdetail.getLoanPeopleSimple(), new itemClick(
                Constants.project_detail_introduction + projectdetail.getProjectId() + "#jkfxx",
                "项目介绍"));
        AbastractListItem item2 = new ProjectDetailItem("借款用途", R.drawable.project_detail_v2_2,
            projectdetail.getLoanUseSimple(), new itemClick(Constants.project_detail_introduction
                                                            + projectdetail.getProjectId()
                                                            + "#jkyt", "项目介绍"));
        AbastractListItem item3 = new ProjectDetailItem("还款来源", R.drawable.project_detail_v2_3,
            projectdetail.getRepaymentWaySimple(), new itemClick(
                Constants.project_detail_introduction + projectdetail.getProjectId() + "#hkly",
                "项目介绍"));
        AbastractListItem item4 = new ProjectDetailItem("资质审核", R.drawable.project_detail_v2_4,
            projectdetail.getCertAuditSimple(), new itemClick(Constants.project_detail_introduction
                                                              + projectdetail.getProjectId()
                                                              + "#zzsh", "项目介绍"));
        AbastractListItem item5 = new ProjectDetailItem("查看全部信息", R.drawable.project_detail_v2_5,
            null, new OnClick() {

                @Override
                public void onClick() {
                    Intent intent = new Intent(mActivity, WebViewPage.class);
                    intent.putExtra("url",
                        Constants.project_detail_introduction + projectdetail.getProjectId());
                    intent.putExtra("title", "项目介绍");
//                    intent.putExtra("PROJECTDETAIL", projectdetail);
                    mActivity.startNewActivityforresult(intent, R.anim.push_left_in,
                        R.anim.push_left_out, ProjectDetailPage.TENDERREQUEST);
                }
            });
        tmp.add(item1);
        tmp.add(item2);
        tmp.add(item3);
        tmp.add(item4);
        tmp.add(item5);
        return tmp;
    }

    public class ProjectDetailItem extends AbastractListItem {

        public String key;
        public int icon;
        public String desc;

        public ProjectDetailItem(String key, int icon, String desc, OnClick onclick) {
            this.key = key;
            this.icon = icon;
            this.desc = desc;
            this.onclick = onclick;
            this.itemLayout = new BaseListItemLayout2();
        }
    }

    class itemClick implements OnClick {
        private String tag;
        private String title;

        public itemClick(String tag, String title) {
            this.tag = tag;
            this.title = title;
        }

        @Override
        public void onClick() {
            //            mActivity.showToast(tag);
            Intent intent = new Intent(mActivity, WebViewPage.class).putExtra("url", tag).putExtra(
                "title", title);
            mActivity.startNewActivity(intent, R.anim.push_left_in, R.anim.push_left_out, false);
        }
    }
}
